import cgi
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.api import users
from entities import *
from Entities import *

from datetime import datetime, date, time

def Add(customerID,appID):
    customer = Customer.get_by_id(customerID)
    app = App.get_by_id(appID)
    currentdate = datetime.today()
    customer_app = Customer_App(CustomerID = customer,AppID = app,DateBuy = currentdate)
    customer_app.put()
    return "Complete"
    
def GetbyCustomer(customerID):
    customer = Customer.get_by_id(customerID)
    buy_list = []
    buys = db.GqlQuery("SELECT * FROM Customer_App WHERE CustomerID = :1",customer)
    for buy in buys:
        buy_dict = {}
        buy_dict["AppID"] = buy.AppID
        buy_dict["DateBuy"] = buy.DateBuy
        buy_list.append(buy_dict)
    tuple_buy = tuple(buy_list)
    return tuple_buy